package net.wanho.customerManage.service.impl;

import net.wanho.commons.exception.DaoException;
import net.wanho.commons.exception.ServiceException;
import net.wanho.commons.factory.BeanFactory;
import net.wanho.customerManage.dao.LinkManDao;
import net.wanho.customerManage.po.LinkMan;
import net.wanho.customerManage.query.LinkManQuery;
import net.wanho.customerManage.service.LinkManService;

import java.util.Date;
import java.util.List;

public class LinkManServiceImpl implements LinkManService {
    private LinkManDao linkManDao = BeanFactory.getBean(LinkManDao.class) ;
    @Override
    public List<LinkMan> selectAllLinkMan() throws ServiceException {
        try {
            return linkManDao.selectAllLinkMan();
        } catch (DaoException e) {
            e.printStackTrace();
            throw new ServiceException(e.getMessage()) ;
        }
    }

    @Override
    public LinkMan selectByIdLinkMan(Integer linkMainId) throws ServiceException {
        try {
            return linkManDao.selectByIdLinkMan(linkMainId) ;
        } catch (DaoException e) {
            e.printStackTrace();
            throw new ServiceException(e.getMessage()) ;
        }
    }

    @Override
    public List<LinkMan> selectByCondLinkMan(LinkManQuery linkManQuery) throws ServiceException {
        try {
            return linkManDao.selectByCondLinkMan(linkManQuery) ;
        } catch (DaoException e) {
            e.printStackTrace();
            throw new ServiceException(e.getMessage()) ;
        }
    }

    @Override
    public Integer insertLinkMan(LinkMan linkMan) throws ServiceException {
        try {
            linkMan.setCreateTime(new Date());
            linkMan.setUpdateTime(new Date());
            linkManDao.insertLinkMan(linkMan) ;
            return  1 ;
        } catch (DaoException e) {
            e.printStackTrace();
            throw new ServiceException(e.getMessage()) ;
        }
    }

    @Override
    public void updateLinkMan(LinkMan linkMan) throws ServiceException {
        try {
            linkMan.setUpdateTime(new Date());
            linkManDao.updateLinkMan(linkMan); ;
        } catch (DaoException e) {
            e.printStackTrace();
            throw new ServiceException(e.getMessage()) ;
        }
    }
}
